
#pragma once

#include <cstdint>
#include <cstring>
#include <memory>
#include <unistd.h>
#include <functional>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "channel.h"
#include "define.h"
#include "udp_socket.h"

class LoopEvent;
class UdpServer
{
public:
    explicit UdpServer(LoopEvent * loop_event);
    ~UdpServer();
    void Listen(int16_t port);
    void DoRead();
    void SetUdpMessage(OnUdpMessage && OnMessage);
    int  SendMsg(UdpBufferPacket & packet, const uint8_t * data, int length);
    int  GetSocketFd() { return  m_udp_socket.GetSocketFd(); }
    void DoReadFunc(int64_t channel_id);
public:
    LoopEvent * m_loop_event;
private:
    UdpSocket m_udp_socket;
    OnUdpMessage m_onMessage;
private:
    uint8_t   m_buffer[65536];
    std::shared_ptr<Channel> m_channel;
};